<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
    var page_type = 'extract';  //设置页面名称
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : '{{ urlfor "RetailController.DataGrid"}}'
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var queryParams = checkQueryTableData(aoData);
            var form = $('#search-form').serializeArray();
            $.each(form, function(i, value){
                queryParams[value.name] = value.value;
            });
            queryParams.IsPayment = '3,5';
			$.post(sSource, JSON.stringify(queryParams),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
            {"bSortable": false, render:function(data, type, full, meta) {
                    return full.Archives.Realname;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Archives.Mobile;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.BusinessName;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.TotalMoney;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.SumPayable;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.AlreadyMoney;
             }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return timetrans(full.CreatedAt);
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    var d = [];
                    d.push('<div class="am-text-left">');
                    switch (full.IsPayment) {
                        case 1:
                            d.push('<div class="am-text-sm">待付款 </div>');
                            break;
                        case 2:
                            d.push('<div class="am-text-sm">待取货</div>');
                            break;
                        case 3:
                            d.push('<div class="am-text-sm">部分退货</div>');
                            break;
                        case 4:
                            d.push('<div class="am-text-sm">已退货</div>');
                            break;
                        case 5:
                            d.push('<div class="am-text-sm">已完成</div>');
                            break;
                    }
                    d.push('</div>');
                    return d.join('');
                }}
			,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"10%",
				"render": function ( data, type, full, meta ) {
                    var d = [];
                    d.push('<a href="{{ urlfor "RetailController.RefundConfirm" }}?sales_id='+ full.Id +'">选择此单退货</a>');
                    return d.join('');
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	$('#query-submit').click(function(){
        $("#dataTables").dataTable().fnDraw(false);

    });
	function reloadTable() {
		$("#dataTables").dataTable().fnDraw(false);
	}

	function dialogReback() {
		reloadTable();
	}
	
	$('#refresh').click(function(){
		reloadTable();
		return false;
	});
</script>